package base;

import android.content.Context;
import android.util.Log;


import com.j256.ormlite.dao.Dao;

import java.util.List;
import java.util.UUID;

import base.dbbean.Life_UserInfo;


/**
 * Created by luoliwen on 16/4/28.
 * 完成对用戶数据库的CRUD的操作
 */
public class Z_UserInfoDao {
    private Context context;
    private Dao<Life_UserInfo, Integer> userDao;
    private Z_DataBaseHelper helper;

    public Z_UserInfoDao(Context context) {
        this.context = context;
        helper = Z_DataBaseHelper.getInstance(context);
        try {
            userDao = helper.getDao(Life_UserInfo.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void addUser(String Wendu, String Fengjizhuangtai, String Zhuansu, String Baojing
            , String Shijian

    ) {
        try {
            Life_UserInfo user = new Life_UserInfo();
            user.setId(UUID.randomUUID().toString());
            user.setWendu(Wendu);
            user.setFengjizhuangtai(Fengjizhuangtai);
            user.setZhuansu(Zhuansu);
            user.setBaojing(Baojing);
            user.setShijian(Shijian);
            userDao.create(user);

        } catch (Exception e) {
            e.printStackTrace();
            Log.e("88888", "" + e);
        }
    }

    List<Life_UserInfo> XTWUserInfos;

    public List<Life_UserInfo> query() {
        try {
            XTWUserInfos = userDao.queryForAll();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return XTWUserInfos;
    }

    public void deleteUser(Life_UserInfo user) {
        try {
            userDao.delete(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
